package com.ws.q1.conifg;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.sql.DataSource;

@Configuration
@ComponentScan("com.ws.q1.controller")
@EnableWebMvc
public class SpringMvcConfig implements  WebMvcConfigurer{
    /**
     * 创建视图解析器
     * @return
     */
    @Bean
    public ViewResolver viewResolverInit(){
        InternalResourceViewResolver viewResolver=new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/");//设置前缀
        viewResolver.setSuffix(".jsp");//设置后缀
        return viewResolver;
    }


    @Bean("multipartResolver")  //方法名是multipartResolver 或者bean中配置名字multipartResolver
    public MultipartResolver multipartResolver(){
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setMaxUploadSize(10000000); //设置上传文件大小最大值
        return multipartResolver;
    }




    /**
     * 启用默认静态资源处理
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
//启用静态处理
        configurer.enable();
    }




}
